import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;

public final class bw {

	private static final Hashtable e = new Hashtable();
	private static final bl f = new bl("R");
	private static Hashtable g;
	public String a;
	public String b;
	public boolean c;
	public Object d;

	public static synchronized bw a(String s, String s1) {
		bw bw1 = (bw) e.get(s);
		if (bw1 == null) {
			(bw1 = new bw(s, s1)).c();
			e.put(s, bw1);
		}
		return bw1;
	}

	public static synchronized bw a(String s) {
		return (bw) e.get(s);
	}

	private static void b(cc cc1) {
		Hashtable hashtable = new Hashtable();
		for (int i = 0; i < cc1.a; i++)
			if (!((aw) cc1.a(i)).a(hashtable))
				return;

		ce.a("Removing unused resources");
		cc cc2 = f.c();
		int j = 0;
		for (int k = cc2.a; j < k; j++) {
			String s1 = cc2.a(j).toString();
			if (!hashtable.containsKey(s1)) {
				ce.a("Removing resource " + s1);
				e.remove(s1);
				f.a(s1);
			}
		}

		Enumeration enumeration = hashtable.keys();
		do {
			if (!enumeration.hasMoreElements())
				break;
			String s = (String) enumeration.nextElement();
			if (e.containsKey(s)
					&& !((Boolean) hashtable.get(s)).booleanValue()) {
				ce.a("Dropping resource " + s);
				e.remove(s);
			}
		} while (true);
		af.a().b();
	}

	public static synchronized void a(cc cc1) {
		b(cc1);
		Runtime runtime;
		long l = (runtime = Runtime.getRuntime()).totalMemory()
				- runtime.freeMemory();
		System.gc();
		long l1 = runtime.totalMemory() - runtime.freeMemory();
		ce.b("Released " + (l - l1) + " bytes");
	}

	private bw(String s, String s1) {
		a = s;
		b = s1;
	}

	public final void a(aw aw1, String s) {
		if (b.equals("image")) {
			if (d == null)
				d = u.a(this);
			aw1.l.a(s, (u) d);
			if (ce.a(31)) {
				if (g == null)
					g = new Hashtable();
				g.put(aw1.e + ":" + s, a);
				return;
			}
		} else {
			if (b.equals("code")) {
				aw1.a(s, this);
				return;
			}
			if (b.equals("theme"))
				aw1.k = this;
		}
	}

	private q b() {
		return f.e(a);
	}

	public final byte[] a() {
		q q1;
		if ((q1 = f.e(a)) != null)
			return q1.g();
		else
			return null;
	}

	private void c() {
		q q1;
		if (!c && (q1 = b()) != null)
			b(q1);
	}

	private void b(q q1) {
		if (b.equals("code")) {
			try {
				d = z.a("", q1.g());
				c = true;
			} catch (IOException ioexception) {
				ce.a(ioexception.toString());
				c = false;
			}
		} else {
			c = true;
		}
	}

	public final void a(q q1) {
		if (!c) {
			f.a(a, q1);
			b(q1);
		}
	}

}